/*
 *  Copyright (C) 2009 Dominik Psenner
 * 
 *   This file is part of WebDAV4JD.
 *
 *  WebDAV4JD is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  WebDAV4JD is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with project-blog.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.lab9.webdav4jd.api.properties;

import com.lab9.webdav4jd.api.exceptions.UnsupportedException;

/**
 * Represents the numeric HTTP status code returned by the server as response.
 * 
 * @author dominik
 * 
 */
public enum ResponseCode {
	OK(200), MULTISTATUS(207), CONFLICT(409);
	
	private int code;
	
	private ResponseCode(final int code) {
		this.code = code;
	}
	
	/**
	 * retrieves the numeric representation of this status code.
	 * 
	 * @return
	 */
	public int getCode() {
		return code;
	}
	
	/**
	 * retrieves the status code for a numeric response code as specified in the HTTP protocol.
	 * 
	 * @param responseCode
	 * @return
	 * @throws UnsupportedException
	 */
	public static ResponseCode get(final int responseCode) throws UnsupportedException {
		for (final ResponseCode c : values()) {
			if (c.getCode() == responseCode) {
				return c;
			}
		}
		throw new UnsupportedException("The status code " + responseCode + " is not supported / unknown.");
	}
}
